package com.lc.pianostudent.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lc.pianostudent.R;
import com.lc.pianostudent.bean.ConversionRecordBean;
import com.lc.pianostudent.bean.HomeNewsBean;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/6/25.
 */

public class ConversionRecordAdapter extends RecyclerView.Adapter<ConversionRecordAdapter.ViewHolder>{


    private Context context;

    private List<ConversionRecordBean> list = new ArrayList<>();

    public ConversionRecordAdapter(Context context, List<ConversionRecordBean> list) {
        this.context = context;
        this.list = list;
    }

    public interface OnItemClickListener {

        void onItemClick(View view, int position);

    }

    private ConversionRecordAdapter.OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(ConversionRecordAdapter.OnItemClickListener listener) {

        this.onItemClickListener = listener;

    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_conversion_record, parent, false);

        ScaleScreenHelperFactory.getInstance().loadViewGroup((ViewGroup) view);

        ConversionRecordAdapter.ViewHolder viewHolder = new ConversionRecordAdapter.ViewHolder(view);

        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {

        holder.time.setText(list.get(position).getCreatetime());

        holder.title.setText(list.get(position).getText());


        setUpItemEvent(holder,position);

    }

    //为RecyclerView添加点击事件
    protected void setUpItemEvent(final ConversionRecordAdapter.ViewHolder holder, final  int position) {

        if (onItemClickListener != null) {

            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    //  int LayoutPosition = holder.getLayoutPosition();

                    onItemClickListener.onItemClick(holder.itemView, position);



                }

            });

        }

    }
    @Override
    public int getItemCount() {
        return list.size();
    }


    //初始化组件
    public static class ViewHolder extends RecyclerView.ViewHolder {

        public TextView title,time;

        public ViewHolder(View itemView) {
            super(itemView);

            time = (TextView) itemView.findViewById(R.id.time);
            title = (TextView) itemView.findViewById(R.id.title);

        }
    }
}
